<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	    <script src="./Public/jquery-1.12.2.min.js"></script>
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	    <style type="text/css">
	    	tr{
	    		font-size: 14px;
	    	}
	    	p{
	    		font-size: 14px;
	    	}
	    </style>
	    <script type="text/javascript">
	    	$(function(){
	    		//声明空数组 用于接收选中的option的gaid
	    		var arr = [];
	    		//select改变的时候触发的事件
	    		$('.spechange').change(function(){
	    			//给每一个select绑定事件
	    			$('.spechange').each(function(){
	    				//获得选中的option的value值 即gaid
		    			var combine = $(this).children('option:selected').attr('value')
		    			//把获得的gaid压进arr数组
		    			arr.push(combine)
	    			})
	    			//发送ajax
	    			$.ajax({
	    				//提交的方式为post
	    				type:"post",
	    				//发送地址
	    				url:"{{U('checkgl')}}",
	    				//发送的数组
	    				data:{combine:arr},
	    				//对返回的数据进行判断
	    				success:function(phpData){
	    					//如果返回1  则代表货品列表中已有选中的货品组合
	    					if(phpData == 1){
	    						//弹出提示消息
	    						alert("货品组合已存在，如果要修改库存，请点击编辑")
	    						//把arr数组清空 不然会一直累加
	    						arr = []
	    						//把option弹回请选择 让用户重新选中货品组合
	    						$('.emptyspec').each(function(){
	    							$(this).attr({selected:'selected' });
	    						})
	    					}else {
	    						//反之 则货品列表中没有选中的组合 用户可以选择 同时也把数组清空；
	    						arr = []
	    					}
	    				}
	    			});
	    		})
	    	})
	    </script>
	</head>
	<body>
		<form action="" method="post">
			<table class="table table-hover">
				<tr class="active">
				  <th width="150">货品ID</th>
				  {{foreach from="$data" value="$v"}}
				  <th width="250">{{$v['taname']}}</th>
				  {{endforeach}}
				  <th width="250">库存</th>
				  <th width="250">货号</th>
				  <th width="250">操作</th>
				</tr>
				{{foreach from="$glData" value="$v"}}
				<tr>
					<td>{{$v['glid']}}</td>
					{{foreach from="$v['gavalue']" value="$vv"}}
					<td>{{$vv}}</td>
					{{endforeach}}
					<td>{{$v['inventory']}}</td>
					<td>{{$v['number']}}</td>
					<td>
						<a href="{{U('editgoodslist',array('glid'=>$v['glid'],'gid'=>$_GET['gid']))}}" class="btn btn-sm btn-warning">编辑</a>
						<a href="javascript:if(confirm('确定删除吗?'))location.href='{{U('delgoodslist',array('glid'=>$v['glid'],'gid'=>$_GET['gid'],'inventory'=>$v['inventory']))}}'" class="btn btn-sm btn-danger">删除</a>
					</td>
				</tr>
				{{endforeach}}
				<tr>
					<td>添加货品</td>
					{{foreach from="$data" value="$v"}}
					<td>
						<select class="form-control spechange" width="150px" name="spec[]">
							<option value="0" class="emptyspec" selected="">-请选择-</option>
							{{foreach from="$v['son']" value="$vv"}}
							<option value="{{$vv['gaid']}}" >{{$vv['gavalue']}}</option>
							{{endforeach}}
						</select>
					</td>
					{{endforeach}}
					<td>
						<input type="text" class="form-control" id="exampleInputName2" name="inventory">
					</td>
					<td>
						<input type="text" class="form-control" id="exampleInputName2" name="number">
					</td>
					<td>
						<button class="btn btn-primary btn-lg" type="submit">确定添加</button>
					</td>
				</tr>
			</table>
			<input type="hidden" name="goods_gid"  value="{{$_GET['gid']}}" />
		</form>
	</body>
</html>
